<template>
    <el-table :data="store.getters['role/getRole']" border style="width: 100%">
        <el-table-column prop="id" label="角色编号"  />
        <el-table-column prop="rolename" label="角色名称"  />

        <el-table-column label="状态">
            <template v-slot="item">
                <el-tag type="success" size="large" plain v-if="item.row.status==1">启用</el-tag>
                <el-tag type="warning" size="large" plain v-else>禁用</el-tag>
            </template>
        </el-table-column>

        <el-table-column label="操作" width="200px">
            <template  v-slot="item">
                <el-button type="primary" @click="edit(item.row.id)">编辑</el-button>
                <el-button type="danger" @click="del(item.row.id)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>
<script lang="ts" setup>
import { useStore } from "vuex"
import { roledelete } from "../../request/api"
import { ElMessage, ElMessageBox } from 'element-plus'
import { defineEmits } from "vue"

let emit = defineEmits(["edit"])
let store = useStore()

const getRole = () =>{
    store.dispatch("role/getRoleAction")
}
getRole()

let edit = (id:number) =>{
   emit("edit",id)
  
}

const del = (id: number) => {
  ElMessageBox.confirm(
    '删除后不可恢复，是否确认删除？',
    {
      confirmButtonText: '删除',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
        roledelete({ id }).then(res => {
        if (res.code == 200) {
          getRole()
          ElMessage({
            type: 'success',
            message: '删除成功！',
          })
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消删除！',
      })
    })
}

</script>
